#include <pbc.h>
#include <glib.h>
#include "celia.h"
#include "pbc_test.h"
#include "kpabe_owner.h"
#include "kpabe_user.h"
#include "kpabe_cloud.h"
#include "streamforce_crypto_KPAbe.h"
#include "utils.h"
#include "common.h"
#include "policy_lang.h"
#include <tr1/unordered_map>

using namespace std::tr1;

typedef struct element_tp{
	element_t element;
} element_wrap;

typedef struct element_wrap_pt{
	unordered_map<int,element_wrap> map;
} ptMap;

struct elementHash{

	inline size_t operator() (element_wrap t) const
	{
	int n= element_length_in_bytes(t.element);
	unsigned char* data = (unsigned char*)malloc(n*sizeof(char));
	element_to_bytes(data,t.element);	
	long val =0;
	for (int i=0; i<n; i++){
		val = 5*val + data[i] + 31;
	}
	return size_t(val);
	}
};

struct equalElement{
	inline bool operator()(element_wrap t1, element_wrap t2) const { 
	if (!element_cmp(t1.element,t2.element))
		return true;
	else 
		return false;
	}
};
typedef struct element_wrap_log{
	unordered_map<element_wrap, int, elementHash, equalElement> map;
} dLogMap;


char** parseAttributeUniverse(char** argv, int size);

char** parseEncryptionAttributes(char** argv, int size);

GByteArray* convertToByteArray(unsigned char* cipher, int len);

int toByteArray(GByteArray* buf, unsigned char **byteArray, int *len);
kpabe_pub_t* convertToPubKey(unsigned char* pubBytes, int pubLen);

kpabe_prv_t* convertToPrvKey(unsigned char* prvBytes, int prvLen);

int convertToElement(unsigned char* bytes, int len, element_t e);

int toPlaintext_simple(int streamId, element_t val);

int toPlaintext_slidingWindow(int streamId, element_t t, element_t mask);

int compare_element_zn(unsigned char* e1, unsigned char *e2);
